#include "CreateAction.h"
#include "EditorCore/Traversers/ChildrenFirstEntityTraverser.h"

namespace editor_core {

	CreateAction::CreateAction() :
		m_createdEntity( 0 )
	{
		m_deleter = new HierarchyDeleter();
	}

	CreateAction::~CreateAction() {
		delete m_deleter;
	}

	bool CreateAction::Commit() {
		m_createdEntity = CreateEntity();

		ChildrenFirstEntityTraverser traverser;
		traverser.Traverse( m_createdEntity, m_deleter );
		return true;
	}

	void CreateAction::Rollback() {
		m_deleter->DeleteHierarchy();
	}

	void CreateAction::Recommit() {
		m_deleter->UndeleteHierarchy();
	}
}
